﻿using System;
using System.Windows.Media.Media3D;
using Perspective.Wpf3D.Primitives;
using Perspective.Wpf3D.Sculptors;
using System.Windows;

namespace Perspective.Wpf3D.Shapes
{
    /// <summary>
    /// 圆台型
    /// A 3D frustum of concial model.
    /// By default, the direction of the cone is the Z axis, and the length is 1.0.
    /// Default radius is 1.0.
    /// </summary>
    public class FrustumConcial3D : ConicalElement3D
    {
         /// <summary>
        /// Static constructor.
        /// No default back material for 3D closed shapes.
        /// </summary>
        static FrustumConcial3D()
        {
            BackMaterialProperty.OverrideMetadata(
                typeof(FrustumConcial3D),
                new PropertyMetadata(
                    null, 
                    VisualPropertyChanged));
        }

        #region Properties

        #region TopRadius 顶面半径
        /// <summary>
        /// Gets or sets the conical top radius.
        /// Default value is 10.0.
        /// </summary>
        public double TopRadius
        {
            get { return (double)GetValue(TopRadiusProperty); }
            set { SetValue(TopRadiusProperty, value); }
        }

        /// <summary>
        /// Identifies the top radius dependency property.
        /// </summary>
        public static readonly DependencyProperty TopRadiusProperty =
            DependencyProperty.Register(
                "TopRadius",
                typeof(double),
                typeof(FrustumConcial3D),
                new UIPropertyMetadata(
                    FrustumConicalSculptor.DefaultTopRadius,
                    VisualPropertyChanged),
                    PositiveDoubleValidateValue);
        #endregion

        #endregion

        /// <summary>
        /// Called by UIElement3D.InvalidateModel() to update the 3D model.
        /// </summary>
        protected override void OnUpdateModel()
        {
            Sculptor = new FrustumConicalSculptor(TopRadius,BottomRadius, Height, SideCount, InitialAngle, RoundingRate);
            base.OnUpdateModel();
        }
    }
}
